package com.rpi;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class RpiMain {

	private static Logger log = LoggerFactory.getLogger(RpiMain.class);

	public static void main(String[] args) {
		springMain();
	}

	private static void springMain() {
		
		ApplicationContext context = 
		    	   new ClassPathXmlApplicationContext(new String[] {"Spring-Context.xml"});
		HomeAutomationStartup startup = (HomeAutomationStartup) context.getBean("homeAutomationStartup");
		startup.initGpioListener();
		
		endless();
	}
	
	private static void endless() {
		try {
			while (true) {
				Thread.sleep(10 * 1000);
				log.trace("Running");
			}
		} catch (InterruptedException e) {
			log.error("main loop interrupted, ending.");
		}
	}

}
